home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / enigma / earcd / emula / arosdv19.lha / AROS / intuition / drawimage.c < prev    next >
C/C++ Source or Header  |  1996-11-08  |  4KB  |  200 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: drawimage.c,v 1.6 1996/11/08 11:28:01 aros Exp $
  4.     $Log: drawimage.c,v $
  5.     Revision 1.6  1996/11/08 11:28:01  aros
  6.     All OS function use now Amiga types
  7.  
  8.     Moved intuition-driver protos to intuition_intern.h
  9.  
  10.     Revision 1.5  1996/10/24 15:51:18  aros
  11.     Use the official AROS macros over the __AROS versions.
  12.  
  13.     Revision 1.4  1996/10/04 15:33:43  digulla
  14.     Optimized: Draws now as many consecutive pixels as possible
  15.  
  16.     Revision 1.3  1996/09/18 14:43:42  digulla
  17.     Made DrawImage work
  18.     After OpenWindow() one *must* call Wait() to allow X11 to draw for now.
  19.  
  20.     Revision 1.2  1996/08/29 13:33:30  digulla
  21.     Moved common code from driver to Intuition
  22.     More docs
  23.  
  24.     Revision 1.1  1996/08/23 17:28:18  digulla
  25.     Several new functions; some still empty.
  26.  
  27.  
  28.     Desc:
  29.     Lang: english
  30. */
  31. #include "intuition_intern.h"
  32. #include <clib/graphics_protos.h>
  33.  
  34. #define DEBUG 1
  35. #include <aros/debug.h>
  36. #include <clib/aros_protos.h>
  37.  
  38. /*****************************************************************************
  39.  
  40.     NAME */
  41.     #include <graphics/rastport.h>
  42.     #include <intuition/intuition.h>
  43.     #include <clib/intuition_protos.h>
  44.  
  45.     AROS_LH4(void, DrawImage,
  46.  
  47. /*  SYNOPSIS */
  48.     AROS_LHA(struct RastPort *, rp, A0),
  49.     AROS_LHA(struct Image    *, image, A1),
  50.     AROS_LHA(LONG             , leftOffset, D0),
  51.     AROS_LHA(LONG             , topOffset, D1),
  52.  
  53. /*  LOCATION */
  54.     struct IntuitionBase *, IntuitionBase, 19, Intuition)
  55.  
  56. /*  FUNCTION
  57.     Draw an image.
  58.  
  59.     INPUTS
  60.     rp - The RastPort to render into
  61.     image - The image to render
  62.     leftOffset, topOffset - Where to place the image.
  63.  
  64.     RESULT
  65.     None.
  66.  
  67.     NOTES
  68.  
  69.     EXAMPLE
  70.  
  71.     BUGS
  72.  
  73.     SEE ALSO
  74.  
  75.     INTERNALS
  76.  
  77.     HISTORY
  78.     29-10-95    digulla automatically created from
  79.                 intuition_lib.fd and clib/intuition_protos.h
  80.  
  81. *****************************************************************************/
  82. {
  83.     AROS_LIBFUNC_INIT
  84.     AROS_LIBBASE_EXT_DECL(struct IntuitionBase *,IntuitionBase)
  85.     ULONG   apen;
  86.     ULONG   drmd;
  87.     WORD    x, y, d, plane;
  88.     WORD    xoff, yoff;
  89.     UWORD * bits[24];
  90.     UWORD   bitmask;
  91.     UWORD   shift;
  92.     UWORD   offset;
  93.     ULONG   pen;
  94.     ULONG   lastPen;
  95. #define START_BITMASK    0x8000L
  96.  
  97.     /* Store important variables of the RastPort */
  98.     apen = GetAPen (rp);
  99.     drmd = GetDrMd (rp);
  100.  
  101.     /* Change RastPort to the mode I need */
  102.     SetDrMd (rp, JAM1);
  103.  
  104.     /* For all borders... */
  105.     for ( ; image; image=image->NextImage)
  106.     {
  107.     /* Use x to store size of one image plane */
  108.     x = ((image->Width + 15) >> 4) * image->Height;
  109.     y = 0;
  110.     shift = image->PlanePick;
  111.  
  112.     for (d=0; d < image->Depth; d++)
  113.     {
  114.         while (!(shift & 1) )
  115.         {
  116.         bits[y ++] = NULL;
  117.         shift >>= 1;
  118.         }
  119.  
  120.         bits[y ++] = image->ImageData + d * x;
  121.         shift >>= 1;
  122.     }
  123.  
  124.     offset    = 0;
  125.  
  126.     yoff = image->TopEdge + topOffset;
  127.  
  128.     for (y=0; y < image->Height; y++, yoff++)
  129.     {
  130.         bitmask = START_BITMASK;
  131.  
  132.         xoff = image->LeftEdge + leftOffset;
  133.  
  134.         for (x=0; x < image->Width; x++, xoff++)
  135.         {
  136.         pen = image->PlaneOnOff;
  137.         shift = 1;
  138.         plane = 0;
  139.  
  140.         for (d=0; d < image->Depth; d++)
  141.         {
  142.             while (!bits[plane])
  143.             {
  144.             plane ++;
  145.             shift <<= 1;
  146.             }
  147.  
  148.             pen |= (bits[plane][offset] & bitmask) ? shift : 0;
  149.  
  150.             plane ++;
  151.             shift <<= 1;
  152.         }
  153.  
  154. /* kprintf (" x=%2d y=%2d   offset=%3d bitmask=%04x bits[]=%04x pen=%d\n"
  155.     , x
  156.     , y
  157.     , offset
  158.     , bitmask
  159.     , bits[0][offset]
  160.     , pen
  161. ); */
  162.  
  163.         if (!x)
  164.         {
  165.             lastPen = pen;
  166.             Move (rp, xoff, yoff);
  167.         }
  168.  
  169.         if (pen != lastPen)
  170.         {
  171.             SetAPen (rp, lastPen);
  172.             Draw (rp, xoff, yoff);
  173.             lastPen = pen;
  174.         }
  175.  
  176.         bitmask >>= 1;
  177.  
  178.         if (!bitmask)
  179.         {
  180.             bitmask = START_BITMASK;
  181.             offset ++;
  182.         }
  183.         }
  184.  
  185.         SetAPen (rp, pen);
  186.         Draw (rp, xoff-1, yoff);
  187.  
  188.         if (bitmask != START_BITMASK)
  189.         offset ++;
  190.     }
  191.  
  192.     }
  193.  
  194.     /* Restore RastPort */
  195.     SetAPen (rp, apen);
  196.     SetDrMd (rp, drmd);
  197.  
  198.     AROS_LIBFUNC_EXIT
  199. } /* DrawImage */
  200.